#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'字符串和日期格式相互转换'

from datetime import datetime

str = '2012-12-13 12:30:40'
dt = datetime.strptime(str, '%Y-%m-%d %H:%M:%S')
print(dt, type(dt)) # 2012-12-13 12:30:40 <class 'datetime.datetime'>

now = datetime.now()
s = now.strftime('%a %b %y')
print(s) # Tue Feb 19
